<template>
  <view>
    <view class="modlist">
      <view class="ul">
        <view class="li borderT">
          <button @tap="myinfoBANKfn">
            <text class="ico ico1"></text>
            <text class="h4">收款账号</text>
          </button>
        </view>
        <view class="li borderT borderB">
          <button @tap="myinfoMOBRZfn">
            <text class="ico ico2"></text>
            <text class="h4">手机认证</text>
            <view class="rzstr">
              <text :class="'span flagstr ' + D.mob_rz_class">{{ D.mob_rz_class == 'LV' ? '已认证' : '未认证' }}</text>
            </view>
          </button>
        </view>
      </view>
    </view>
    <view v-if="div_myinfoMOBRZ_form" class="mask2 alpha0_100">
      <view class="div_box big_normal div_myinfo_box" style="--div_box_width: 82%; --div_box_height: 680rpx">
        <view class="close ico" @tap="my_info_closeFn"></view>
        <form class="my_cert" @submit.stop.prevent="submit_mob_Fn">
          <view class="h1">
            <view class="span title">手机认证</view>
            <text :class="'span flagstr ' + D.mob_rz_class">{{ D.mob_rz_class == 'LV' ? '已认证' : '未认证' }}</text>
            <text class="font">{{ D.mob_hide }}</text>
          </view>
          <view class="dl">
            <view class="dt">
              <text class="i ico"></text>
            </view>
            <view class="dd">
              <input
                  id="mob"
                  :value="value_mob"
                  class="input_login"
                  maxlength="11"
                  name="mob"
                  pattern="[0-9]*"
                  placeholder="输入手机号"
                  placeholderClass="placeholder"
                  type="number"
                  @input="value_mobFn"
              />
              <text id="reset_rz" class="span ico"></text>
            </view>
          </view>
          <view class="dl">
            <view class="dt">
              <text class="i ico"></text>
            </view>
            <view class="dd">
              <input
                  id="verify"
                  :value="value_verify"
                  class="input_login"
                  maxlength="4"
                  name="verify"
                  pattern="[0-9]*"
                  placeholder="输入验证码"
                  placeholderClass="placeholder"
                  type="number"
              />
              <text v-if="miao == 0" class="yzmbtn" @tap="getyzmFn">重新获取</text>
              <text v-else-if="miao < miao2 && miao > 0" class="yzmbtn">
                请查收手机短信
                <text class="red">{{ miao }}S</text>
              </text>
              <text v-else class="yzmbtn" @tap="getyzmFn">获取验证码</text>
            </view>
          </view>
          <button :style="'--color:' + color + ';--rgbcolor:' + rgbcolor + ';'" class="btn4 ico" formType="submit">
            提交认证
          </button>
        </form>
      </view>
    </view>
    <jp-cropper-watermark :height="height" :maxHeight="max_width" :maxWidth="max_height" :url="photo" :width="width"
                          mode="free" @cancel="oncancel" @ok="onok"></jp-cropper-watermark>

  </view>
</template>

<script>
import globalUtils from "../../res/www.a9a.cn";
import i from "../../res/www.a9a.cn";
import JpCropperWatermark
  from "../../uni_modules/jp-cropper-watermark/components/jp-cropper-watermark/jp-cropper-watermark.vue";

var a;
var n = require('../../@babel/runtime/helpers/defineProperty');
var t = require('../../res/www.a9a.cn.js');
var app = getApp();
export default {
  components: {JpCropperWatermark},
  computed: {
    globalUtils() {
      return globalUtils
    }
  },
  data() {
    return {
      miao: 120,
      miao2: 120,
      nTitle: '账户/认证',
      mask_class: 'alpha0_100',
      color: '',
      rgbcolor: '',
      D: {
        mob_rz_class: '',
        alipay_username: '',
        alipay_truename: '',
        bank_name: '',
        bank_name_kaihu: '',
        bank_card: '',
        id_card_num: '',
        bank_truename: '',
        bank_phone: '',
        mob_hide: '',
        front_id_card: '',
        front_id_card_dbname: '',
        reverse_id_card: '',
        reverse_id_card_dbname: '',
      },
      photo: '',
      photo_is: 0,
      width: 500,
      height: 400,
      max_width: 600,
      max_height: 500,
      isFlao: {
        isZfb: false,
        isYhk: true,
      },
      div_myinfoBANK_form: false,
      div_myinfoMOBRZ_form: false,
      value_mob: '',
      ss: '',
      value_verify: ''
    };
  },
  onLoad: function (a) {
    var that = this;
    var e = this;
    app.globalData.get_config('_ZEAI').then(function (a) {
      e.setData({
        color: app.globalData._ZEAI.color,
        rgbcolor: t.c16_rgb(app.globalData._ZEAI.color)
      });
    });
    app.globalData.get_openid().then(function (a) {
      that.init();
    });
  },
  methods: {
    init: function () {
      var that = this;
      a = uni.getStorageSync('COOK_U');
      app.globalData.ajax({
        url: 'tg.php',
        data: {
          submitok: 'myinfo_BANK',
          openid: a.openid
        },
        success: function (a) {
          if (1 == a.flag) {
            that.setData({
              D: a.D
            });
            that.D.reverse_id_card_dbname = that.extractPathAfterBase(a.D.reverse_id_card, app.globalData.WWW + 'up/')
            that.D.front_id_card_dbname = that.extractPathAfterBase(a.D.front_id_card, app.globalData.WWW + 'up/')
            console.log(that.D.reverse_id_card_dbname);
            console.log(that.D.front_id_card_dbname);
          } else {
            uni.showToast({
              title: a.msg,
              icon: 'none',
              mask: true
            });
          }
        }
      });
    },
    // 截取上传路径
    extractPathAfterBase(url, basePath) {
      if (!url || !basePath) return '';
      const index = url.indexOf(basePath);
      return index !== -1 ? url.substring(index + basePath.length) : '';
    },
    myinfoBANKfn: function () {
      // this.setData({
      //   div_myinfoBANK_form: true
      // });
      uni.navigateTo({
        url: '/pagesB/bankAuthentication/bankAuthentication',
      })
    },

    myinfoMOBRZfn: function () {
      this.setData({
        div_myinfoMOBRZ_form: true
      });
    },

    myinfoBANKsubmitFn: function (e) {
      var that = this;
      var s = e.detail.value;

      let arrExp = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]; //加权因子
      let arrValid = [1, 0, "X", 9, 8, 7, 6, 5, 4, 3, 2]; //校验码

      if (app.globalData.empty(s.bank_truename)) return uni.showToast({
        title: '请输入【卡号姓名】',
        icon: 'none',
        mask: true
      });
      if (app.globalData.empty(s.bank_phone)) return uni.showToast({
        title: '请输入【银行卡绑定手机号】',
        icon: 'none',
        mask: true
      });
      if (/^\d{17}\d|x$/i.test(s.id_card_num)) {
        let sum = 0,
            idx;
        for (let i = 0; i < s.id_card_num.length - 1; i++) {
          // 对前17位数字与权值乘积求和
          sum += parseInt(s.id_card_num.substr(i, 1), 10) * arrExp[i];
        }
        // 计算模（固定算法）
        idx = sum % 11;
        // 检验第18为是否与校验码相等
        if (arrValid[idx] == s.id_card_num.substr(17, 1).toUpperCase()) {

        } else {
          uni.showToast({
            title: '身份证号码错误！',
            icon: 'none',
            duration: 2000
          });
          return;
        }
      } else {
        uni.showToast({
          title: '身份证号码不正确！',
          icon: 'none',
          duration: 2000
        });
        return;
      }
      if (app.globalData.empty(s.bank_card)) return uni.showToast({
        title: '请输入【银行卡号】',
        icon: 'none',
        mask: true
      });
      if (app.globalData.empty(s.front_id_card_dbname)) return uni.showToast({
        title: '请上传【身份证(人像面)】',
        icon: 'none',
        mask: true
      });
      if (app.globalData.empty(s.reverse_id_card_dbname)) return uni.showToast({
        title: '请上传【身份证(国徽面)】',
        icon: 'none',
        mask: true
      });
      console.log('表单数据', s)
      app.globalData.ajax({
        url: 'tg.php',
        data: {
          submitok: 'myinfo_BANK_modupdate',
          openid: a.openid,
          alipay_truename: s.alipay_truename,
          alipay_username: s.alipay_username,
          bank_card: s.bank_card,
          id_card_num: s.id_card_num,
          bank_name: s.bank_name,
          bank_name_kaihu: s.bank_name_kaihu,
          bank_truename: s.bank_truename,
          bank_phone: s.bank_phone,
          front_id_card: s.front_id_card_dbname,
          reverse_id_card: s.reverse_id_card_dbname,
        },
        success: function (a) {
          var o;
          if (1 == a.flag) {
            console.log('获取值')
            uni.showModal({
              content: '根据国家规定，银行卡信息需完成认证签约，请先完成签署。未签约将导致提现失败，请长按下方二维码签约',
              confirmColor: that.color,
              confirmText: '朕知道了',
              showCancel: false,
              success: function (res) {
                uni.showToast({
                  title: a.msg,
                  mask: true,
                  duration: 3000
                })
                that.setData(
                    (n((o = {}), 'D.alipay_truename', s.alipay_truename),
                        n(o, 'D.alipay_username', s.alipay_username),
                        n(o, 'D.bank_card', s.bank_card),
                        n(o, 'D.id_card_num', s.id_card_num),
                        n(o, 'D.bank_name', s.bank_name),
                        n(o, 'D.bank_name_kaihu', s.bank_name_kaihu),
                        n(o, 'D.bank_truename', s.bank_truename),
                        n(o, 'D.bank_phone', s.bank_phone),
                        n(o, 'D.front_id_card_dbname', s.front_id_card_dbname),
                        n(o, 'D.reverse_id_card_dbname', s.reverse_id_card_dbname),
                        n(o, 'div_myinfoBANK_form', false),
                        o)
                );
              }
            });

          } else {
            (a.this = that), (a.url = 'no'), t.sorry(a);
          }
        }
      });
    },

    value_mobFn: function (a) {
      this.setData({
        value_mob: a.detail.value
      });
    },

    getyzmFn: function (n) {
      var e = this.value_mob;
      if (t.ifmob(e)) {
        var that = this;
        a = uni.getStorageSync('COOK_U');
        app.globalData.ajax({
          url: 'tg.php',
          data: {
            submitok: 'ajax_get_verify',
            mob: e,
            kind: 'tg_mob_rz',
            openid: a.openid
          },
          success: function (a) {
            1 == a.flag
                ? (uni.showToast({
                  title: a.msg,
                  icon: 'none',
                  mask: true
                }),
                    that.setData({
                      ss: a.ss,
                      value_verify: '',
                      miao: that.miao2 - 1
                    }),
                    (that.time = setInterval(function () {
                      that.setData({
                        miao: that.miao - 1
                      });
                      if (0 == that.miao) {
                        clearInterval(that.time);
                      }
                    }, 1000)))
                : uni.showModal({
                  content: a.msg,
                  confirmColor: that.color,
                  confirmText: '朕知道了',
                  showCancel: false,
                  success: function (a) {
                  }
                });
          }
        });
      } else {
        uni.showToast({
          title: '请输入正确的【手机号】',
          icon: 'none',
          mask: true
        });
      }
    },

    submit_mob_Fn: function (e) {
      const url = 'http://m.yunhuotec.com/cloudgainMobile/#/contractedUser?platformId=20250806984547229510574080'
      var that = this;
      var s = e.detail.value.mob;
      var m = e.detail.value.verify;
      t.ifmob(s)
          ? t.ifint(m)
              ? ((a = uni.getStorageSync('COOK_U')),
                  app.globalData.ajax({
                    url: 'tg.php',
                    data: {
                      submitok: 'myinfo_MOBRZ_update',
                      mob: s,
                      ss: that.ss,
                      verify: m,
                      openid: a.openid
                    },
                    success: function (a) {
                      1 == a.flag
                          ? (uni.showToast({
                            title: a.msg,
                            mask: true,
                            duration: 3000
                          }),
                              setTimeout(function () {
                                var a;
                                that.setData(
                                    (n(
                                        (a = {
                                          div_myinfoMOBRZ_form: false
                                        }),
                                        'D.mob_rz_class',
                                        'LV'
                                    ),
                                        n(a, 'miao', 0),
                                        a)
                                );
                              }, 3000))
                          : uni.showModal({
                            content: a.msg,
                            confirmColor: that.color,
                            confirmText: '朕知道了',
                            showCancel: false,
                            success: function (a) {
                            }
                          });
                    }
                  }))
              : uni.showToast({
                title: '请输入正确的【验证码】',
                icon: 'none',
                mask: true
              })
          : uni.showToast({
            title: '请输入正确的【手机号】',
            icon: 'none',
            mask: true
          });
    },

    my_info_closeFn: function () {
      this.setData({
        div_myinfoBANK_form: false,
        div_myinfoMOBRZ_form: false
      });
    },
    // 上传身份证图像
    my_info_photo_s_addFn: function (n) {
      var that = this;
      uni.chooseMedia({
        count: 1,
        mediaType: ['image'],
        sourceType: ['album', 'camera'],
        sizeType: ['original', 'compressed'],
        success: function (e) {
          that.setData({
            photo: e.tempFiles[0].tempFilePath,
            photo_is: n,
          });
        }
      });
    },
    // 裁剪后的图片
    onok(ev) {
      const that = this;
      uni.uploadFile({
        url: app.globalData.WWW + '/api/wxxcx/tg.php',
        filePath: ev.path,
        name: 'pic',
        formData: {
          submitok: 'myinfo_id_card',
          openid: a.openid
        },
        success: function (t) {
          console.log('有数据吗', t)
          that.photo = ''
          if (1 == (t = i.jsoneval(t.data)).flag) {
            if (that.photo_is === 1) {
              that.setData({
                'D.front_id_card': t.id_card_photo_s,
                'D.front_id_card_dbname': t.dbname
              })
            } else {
              that.setData({
                'D.reverse_id_card': t.id_card_photo_s,
                'D.reverse_id_card_dbname': t.dbname
              })
            }
          } else {
            uni.showModal({
              content: t.msg,
              confirmColor: that.color,
              confirmText: '朕知道了',
              showCancel: false,
              success: function (t) {
              }
            });
          }
        }
      });
    },
    oncancel() {
      this.photo = ''
    },

  }
};
</script>
<style>
@import 'my_info.css';
</style>
